#include "node.h"

#include "inodedata.h"

using namespace core;

Node* Node::create(INodeData* data)
{
    return new Node(data);
}

Node::~Node()
{
    if (m_data != 0)
    {
        m_data->registerNode(0);
    }
}

const INodeData* Node::getData() const
{
    return m_data;
}

QSet<Node* > Node::getIncomingConnections() const
{
    return m_incomingConnections;
}

QSet<Node* > Node::getOutgoingConnections() const
{
    return m_outgoingConnections;
}

Node::Node(INodeData* data) : m_data(data),
    m_incomingConnections(),
    m_outgoingConnections()
{
    if (data != 0)
    {
        data->registerNode(this);
    }
}

void Node::addIncoming(Node* node)
{
    m_incomingConnections.insert(node);
}

void Node::addOutgoing(Node* node)
{
    m_outgoingConnections.insert(node);
}

void Node::removeIncoming(Node* node)
{
    m_incomingConnections.remove(node);
}

void Node::removeOutgoing(Node* node)
{
    m_outgoingConnections.remove(node);
}

